/**
 * @class   wosh::devices::JSpaceCommBundle
 * @brief   \ref wosh::interfaces::services::CommunicatorService "Communicator Service"
 *          for Philiphs TV equipped with jointSPACE technology.
 *
 * \see page_jointspace
 *
 *
 * @ingroup Devices
 ****************************************************************************
 * @version 0.8.462 $Id: JSpaceCommBundle.h 2891 2010-08-12 01:58:59Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/*! 
 * \section page_jointspace_overview jointSPACE Overview
 *
 * jointSPACE is a new 'framework' from/for Philips TV (2009 and later) which
 * allows developers to render data on TV and interact with user from a PC.
 *
 * Remote applications are applications running on external devices,
 * making use of TV capabilities to render GFX and media. 
 *
 * External devices can be any computing device including iPod/iPhone, game consoles, PDA, lighweight PC, PC servers, MAC...
 *  - Remote applications are using the IP network (wired or wireless) to communicate with the TV.
 *  - Remote applications can be used to extend TV functionality with customizable features,integrated together with "standard" TV applications.
 *  - Remote applications can be controlled with the TV remote.
 *  - Remote applications are making use of DirectFB/VooDoo technologies and follow (joint)SPACE architecture rules. 
 *
 * Two kind of remote applications are currently supported:
 *  - Applications to control the TV remotely (inject events like keys over the network)
 *  - Applications making use of the TV resources to render GFX and media content 
 *
 * First of all you need a Philips TV with networking capabilities:
 *  - 2k9 models (8000-9000 range)
 *  - 2K10 models(7000-9000 range) 
 * Those include current NetTV capable Philips TVs.
 *
 * \see     http://jointspace.sourceforge.net/
 * \see     http://www.directfb.org/

 * \section page_jointspace_setup jointSPACE Setup
 *
 * Remote applications are developped to run on remote systems, therefore you also need:
 *  - the compiler toolchain to create executables for your system (typically gcc and make toolchains)
 *  - the jointSPACE DirectFB/VooDoo client package for your system 
 *
 *
 *
 * On POSIX (tested on Linux Debian Lenny)
 * Download and uncompress DirectFB_Voodoo_linux_ia32.tar.gz into /libs/3rdparty
 *
 *
 *
 *
 *
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Bundles_Devices_JSpaceComm_H__
 #define __WOSH_Bundles_Devices_JSpaceComm_H__

 #include <core/BundleGeneric.h>
 #include <core/Thread.h>
 
 #include <core/Communicator.h>
 #include <interfaces/services/CommunicatorService.h>
 #include <interfaces/devices/JSpaceComm.h>

 #include "IJSpaceCommListener.h"

class JSpaceCommImpl;

namespace wosh {
 namespace devices {

 #define _JSpaceComm_NAME						"JSpaceComm"
 #define _JSpaceComm_VERSION					0.01


class JSpaceCommBundle :	public BundleGeneric,
							public virtual wosh::interfaces::devices::JSpaceComm,
							public virtual wosh::interfaces::services::CommunicatorService, 
							public virtual IJSpaceCommListener
 {
	WOSH_BUNDLE(wosh::devices::JSpaceCommBundle)
	WOSH_BUNDLE_INTERFACE("wosh::interfaces::devices::JSpaceComm")
	WOSH_BUNDLE_SINGLETON(0,0)

	public:
		/**
		 * @brief   Empty constructor, init bundle and vars, Properties and Methods.
		 */
		JSpaceCommBundle();
		/**
		 * @brief   Empty destructor, may (synch) stop bundle and internal threads when still running
		 */
		virtual ~JSpaceCommBundle();


	public:
		WRESULT bundleStart();
		WRESULT bundleStop();
		WRESULT bundleDiagnostic();

		void busMessage( const Message& message, const Bus* source );

//@}
/** @name Device Interface
 * @{
 ******************************************************************************/
	public:
		wosh::interfaces::Device::DEVICE_STATE getDeviceState() const { return this->devState; }

//@}
/** @name JSpaceComm Interface
 * @{
 ******************************************************************************/
	public:

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:


//@}
/** @name Communicator Interface
 * @{
 ******************************************************************************/
	public:
		bool isUserReachable( const std::string& wosh_username );
		WRESULT sendMessageToUser( const std::string& wosh_username, const std::string& message );
		WRESULT sendMessageTo( const std::string& user_phonenumber, const std::string& message );
		WRESULT notify( const Notification* notification, const Message* notification_message = NULL );

//@}
/** @name IPropertiesProviderListener interface
 * @{
 ******************************************************************************/
 	public:
		bool updatingProperty( bool& do_update, const Variant& value_proposed, Property& property_current, const PropertiesProvider* source );
//@}
	private:
		Response* mmDoSendMessageToUser( const Message* requestMessage );

	protected:
		BusConnector BusDevices;			///< register myself & work as Device too
		JSpaceCommImpl* devWorker;		///< real implementation

		wosh::interfaces::Device::DEVICE_STATE devState;		///< current state of device


}; // class def

 }; // namespace devices
}; // namespace wosh

#endif //__WOSH_Bundles_Devices_JSpaceComm_H__
